From 25551d9192f5192531ab7ef2d7ced7c01bfde415 Mon Sep 17 00:00:00 2001 From: Jimi Xenidis Date: Fri, 3 Nov 2006 16:53:17 -0500 Subject: [PATCH] [XEN][POWERPC] The VIO rewrite Once you figure it all out, its time to do a rewrite, lots of code I thougth I needed is now removed and less PPC specific code now exists. This patch uses the MEMORY_HOTPLUG system to add a region to the Kernel Linear Mapping that will be used exclusively to map in Granted/Foreign pages. This creates "struct page" objects in Linux which are necessary to perform VIO operations. When one of these pages are grant_mapped the pfn2mfn() translation in Xen is updated to reflect the association and the subsequent H_ENTER() from the domain will contain the correct mapping. Signed-off-by: Jimi Xenidis Signed-off-by: Hollis Blanchard --- xen/arch/powerpc/domain.c | 7 +++++++ xen/arch/powerpc/mm.c | 24 +++++++++++++++++++++++- xen/arch/powerpc/ofd_fixup.c | 2 +- xen/include/asm-powerpc/domain.h | 3 +++ xen/include/asm-powerpc/grant_table.h | 4 ---- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/xen/arch/powerpc/domain.c b/xen/arch/powerpc/domain.c index f2fe28048c..31a594d03c 100644 --- a/xen/arch/powerpc/domain.c +++ b/xen/arch/powerpc/domain.c @@ -88,6 +88,12 @@ int arch_domain_create(struct domain *d) INIT_LIST_HEAD(&d->arch.extent_list); + d->arch.foreign_mfn_count = 1024; + d->arch.foreign_mfns = xmalloc_array(uint, d->arch.foreign_mfn_count); + BUG_ON(d->arch.foreign_mfns == NULL); + + memset(d->arch.foreign_mfns, -1, d->arch.foreign_mfn_count * sizeof(uint)); + return 0; } @@ -294,6 +300,7 @@ void domain_relinquish_resources(struct domain *d) relinquish_memory(d, &d->xenpage_list); relinquish_memory(d, &d->page_list); free_extents(d); + xfree(d->arch.foreign_mfns); return; } diff --git a/xen/arch/powerpc/mm.c b/xen/arch/powerpc/mm.c index 8a91cbe51d..d6bc94b4a5 100644 --- a/xen/arch/powerpc/mm.c +++ b/xen/arch/powerpc/mm.c @@ -93,6 +93,26 @@ void share_xen_page_with_privileged_guests( unimplemented(); } +static ulong foreign_to_mfn(struct domain *d, ulong pfn) +{ + + pfn -= 1UL << cpu_foreign_map_order(); + + BUG_ON(pfn >= d->arch.foreign_mfn_count); + + return d->arch.foreign_mfns[pfn]; +} + +static int set_foreign(struct domain *d, ulong pfn, ulong mfn) +{ + pfn -= 1UL << cpu_foreign_map_order(); + + BUG_ON(pfn >= d->arch.foreign_mfn_count); + d->arch.foreign_mfns[pfn] = mfn; + + return 0; +} + static int create_grant_va_mapping( unsigned long va, unsigned long frame, struct vcpu *v) { @@ -101,6 +121,7 @@ static int create_grant_va_mapping( BUG(); return GNTST_permission_denied; } + set_foreign(v->domain, va >> PAGE_SHIFT, frame); return GNTST_okay; } @@ -112,6 +133,7 @@ static int destroy_grant_va_mapping( BUG(); return GNTST_permission_denied; } + set_foreign(d, addr >> PAGE_SHIFT, ~0UL); return GNTST_okay; } @@ -388,7 +410,7 @@ ulong pfn2mfn(struct domain *d, ulong pfn, int *type) /* quick tests first */ if (pfn & foreign_map_pfn) { t = PFN_TYPE_FOREIGN; - mfn = pfn & ~(foreign_map_pfn); + mfn = foreign_to_mfn(d, pfn); } else if (pfn >= max_page && pfn < (max_page + NR_GRANT_FRAMES)) { /* Its a grant table access */ t = PFN_TYPE_GNTTAB; diff --git a/xen/arch/powerpc/ofd_fixup.c b/xen/arch/powerpc/ofd_fixup.c index 816fd19189..3cb498dda9 100644 --- a/xen/arch/powerpc/ofd_fixup.c +++ b/xen/arch/powerpc/ofd_fixup.c @@ -354,7 +354,7 @@ static ofdn_t ofd_xen_props(void *m, struct domain *d, start_info_t *si) /* tell dom0 where ranted pages go in the linear map */ val[0] = cpu_foreign_map_order(); - val[1] = max_page; + val[1] = d->arch.foreign_mfn_count; ofd_prop_add(m, n, "foreign-map", val, sizeof (val)); n = ofd_node_add(m, n, console, sizeof (console)); diff --git a/xen/include/asm-powerpc/domain.h b/xen/include/asm-powerpc/domain.h index 304cb6c950..4c7693e437 100644 --- a/xen/include/asm-powerpc/domain.h +++ b/xen/include/asm-powerpc/domain.h @@ -41,6 +41,9 @@ struct arch_domain { /* list of extents beyond RMA */ struct list_head extent_list; + uint foreign_mfn_count; + uint *foreign_mfns; + /* I/O-port access bitmap mask. */ u8 *iobmp_mask; /* Address of IO bitmap mask, or NULL. */ diff --git a/xen/include/asm-powerpc/grant_table.h b/xen/include/asm-powerpc/grant_table.h index 32920dad0a..81b1b1ed62 100644 --- a/xen/include/asm-powerpc/grant_table.h +++ b/xen/include/asm-powerpc/grant_table.h @@ -69,8 +69,4 @@ static inline uint cpu_foreign_map_order(void) /* 16 GiB */ return 34 - PAGE_SHIFT; } - -#define GNTTAB_DEV_BUS(f) \ - ((f) | (1UL << (cpu_foreign_map_order() + PAGE_SHIFT))) - #endif /* __ASM_PPC_GRANT_TABLE_H__ */ -- 2.30.2